import java.util.*;

public class CalendarSeeker
{
	static final int MIN_YEAR = 2000;
	static final int MAX_YEAR = 2012;
	
	public static int validateDay( int day, int month, int year )
	{
		if ( day > 1 && day <= 31 ){
		
			//check February
			if ( month == 2) 
			{
				if ( isLeapYear( year) && day > 29 )
				{
					System.out.println("Input day is not in range. Value \"1\" is accepted.");
					return 1;
				}			
				if ( ( !isLeapYear( year) ) && day > 28 )
				{
					System.out.println("Input day is not in range. Value \"1\" is accepted.");
					return 1;
				}
			}
			
			if ( ( month == 4 || month == 6 || month == 9 || month == 11 ) && day > 30 )
			{
				System.out.println("Input day is not in range. Value \"1\" is accepted.");
				return 1;
			}
			
			return day;
			
		}else{
		
			System.out.println("Input day is not in range. Value \"1\" is accepted.");
			return 1;
		}
		
	}
	
	public static int validateMonth( int month )
	{
		if ( month < 1 || month > 12 ) 
		{
				System.out.println("Input month is not in range. Value \"1\" is accepted.");
				return 1;
		}
		
		return month;
	}
	
	public static int validateYear( int year)
	{
		if ( year < MIN_YEAR || year > MAX_YEAR ) 
		{
			System.out.println("Input year should be in range " + MIN_YEAR + ".." + MAX_YEAR + " Year " + MIN_YEAR + " is accepted.");
			return MIN_YEAR;
		}
		return year;
	}
	public static boolean isLeapYear( int year )
	{		
		if ( year % 4 == 0){

			if ( year % 100 != 0) {
				return true;
			}
			else if ( year % 400 == 0) {
				return true;
			} else {
				return false;
			}
			
		}else{
			return false;
		}
	
	}
	
	public static int getDayOfWeek(int dayInput, int monthInput, int yearInput)
	{
		//Gaussian algorithm is used
		int year;
			if ( monthInput == 0 || monthInput == 1 ) {
				year = yearInput - 1; }
			else year = yearInput;
			
		int shiftedMonth = ( ( monthInput + 9 ) % 12 ) + 1;
			
		Integer yearWrapped = new Integer(year);
		
		String firstTwoDigitsOfYear_String = yearWrapped.toString().substring(0,1);
		String lastTwoDigitsOfYear_String =  yearWrapped.toString().substring(2,3);
		
		int firstTwoDigitsOfYear = Integer.parseInt(firstTwoDigitsOfYear_String);
		int lastTwoDigitsOfYear = Integer.parseInt(lastTwoDigitsOfYear_String);
		
		int dayOfWeek = ( 
								   dayInput + (int)( 2.6 * shiftedMonth - 0.2 ) 
								   + lastTwoDigitsOfYear + (int)( lastTwoDigitsOfYear / 4 ) 
								   + (int)( firstTwoDigitsOfYear / 4 ) 
								   + 2 * firstTwoDigitsOfYear
						);
						
		return ( dayOfWeek % 7 );
		
	}
	
	public static void printDayOfWeek(int day)
	{
		if ( day < 0 || day > 7){
		
			System.out.println("Wrong day number input!");
			
		}else{
		
			String[] dayOfWeek = { 
									"Monday", "Tuesday", "Wednesday", "Thursday",
									"Friday", "Saturday", "Sunday" 
								 };
					   
			System.out.println( dayOfWeek[day] );
		}
		
	}
	
	public static void main( String[] args )
	{	
			
		int day;
		int month;
		int year;
		
		Scanner inputScanner = new Scanner( System.in );
		
		System.out.println("Enter date in numerical format: day(1..31) month(1..12) year(" + MIN_YEAR + ".." + MAX_YEAR + ")");
		try 
		{
			day = inputScanner.nextInt();
			month = inputScanner.nextInt();
			year = inputScanner.nextInt();
		}
		catch( InputMismatchException e )
		{
			System.out.println("Input is not correct. Try not to use symbols other than digits.");
			return;
			
		}
		
		inputScanner.close();
		
		year = validateYear( year );
		month = validateMonth( month );
		day = validateDay( day, month, year );
		
		System.out.println( day + " " + month + " " + year );
		printDayOfWeek( getDayOfWeek( day, month, year ) );
		
	}
}